<?php

namespace App\Http\Requests\Admin\User\User;

use App\Models\Role;
use Illuminate\Foundation\Http\FormRequest;

class AllotRolesRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'roles'=>[
                'nullable',
                'array',
                function($attribute,$value,$fail){
                    $count = Role::whereIn('id',$value)->count('id');
                    if($count!=count($value)){
                        $fail(":attribute错误");
                    }
                }
            ]
        ];
    }
    public function messages()
    {
        return ['roles'=>'角色'];
    }
}
